<?php


class templates { 
 
var $path = PATH; 
 public function __construct()
  {
		
		$gb_dal = new DAL;

  }

//форма добавления сообщения
public function template_form()
{
	
 
  function error($messageid, $coment, $comentname,$error)
  {
    if($error) echo '<br><font color=#880000>'.$error.'</font>';
  }
  
	include './views/template_add_message.html';
 
	
}

//добавленеи сообщения
public function addMessage($message, $name)
{
    $gb_dal = new DAL;
	$gb_dal->addMessage($message, $name);
	header('Location: '.PATH."?page=1");
}

//добавленеи сообщения
public function addComent($messageid, $message, $name)
{
  
    
    $gb_dal = new DAL;
	$gb_dal->addComent($messageid, $message, $name);
    
	
	if (DEBUGPRINT) echo '<br> templates addComent END';
}


//удаление сообщения
public function DelMessage($id)
{
    $gb_dal = new DAL;
	$gb_dal->DelMessage($id);
	header('Location: '.PATH."?page=1");
}

public function DelComent($id)
{
    $gb_dal = new DAL;
	$gb_dal->DelComent($id);
	header('Location: '.PATH."?page=1");
	die;
}



public function change_message($messageid, $message, $name)
{
	$gb_dal = new DAL;	
	$gb_dal-> change_message($messageid, $message, $name);
		
}

public function change_coment($messageid, $message, $name)
{
	$gb_dal = new DAL;	
	$gb_dal-> change_coment($messageid, $message, $name);
		
}


public function showmessages()
{
	$gb_dal = new DAL;
	$messages = $gb_dal->getAllMessages();
	foreach ($messages as $message){
	  	    $this->template_show_message($message['id'],
   							 	     $message['name'],
   							   		 $message['message'],
   							   		 $message['datetime']
							   		);
		
		
		
		$coments = $gb_dal->getAllComents($message['id']);
		foreach ($coments as $coment) {
				$this->template_show_coment($coment['comentid'],
											$coment['comentname'],
			  								$coment['coment'],
			  								$coment['comentdatetime']
											);
				}			
			}
	
}	

//форма добавления комментария
public function template_form_addComent($messageid)
{
    $gb_dal = new DAL;
	$messages = $gb_dal->getMessage($messageid);
	$row = $messages[0]; 

	include './views/template_add_coment.html';
    $coments = $gb_dal->getAllComents($messageid);
				
			foreach ($coments as $coment) {
            $this->template_show_coment($coment['comentid'],
											$coment['comentname'],
			  								$coment['coment'],
			  								$coment['comentdatetime']
											);
        }
	  unset($coment);
}


public function template_form_change_message($messageid)
{
    $gb_dal = new DAL;
	$messages = $gb_dal->getMessage($messageid);
	$row = $messages[0]; 
    include './views/template_change_message.html';
		
}

public function template_form_change_comment($comentid)
{
	
	$gb_dal = new DAL;
	$messages = $gb_dal->getComments($comentid);	
	$row = $messages[0]; 
		//$gb_dal-> change_comment($comentid, $message, $name);	
    include './views/template_change_comment.html';
	
}

private function template_show_message($id, $name, $message, $datetime)
{
	//Генерирование ссылок
 $message_del 	  = PATH.'?del='.$id;
 $message_coment  = PATH.'?coment='.$id;
 $message_change  = PATH.'?change='.$id;
include './views/template_show_body.html';
}


private function template_show_coment($comentid, $comentname, $coment, $comentdatetime)
{
	
	//Генерирование ссылок
 $coment_del=PATH.'?delcoment='.$comentid;
 $coment_change=PATH.'?changecoment='.$comentid;
 	include './views/template_show_coments.html';
}






}

